import { BaseInfos } from './baseInfo';
let _BaseInfos = BaseInfos;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import BaseInfoMock from './mk/mng/card/baseInfoMock';
 * BaseInfoMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/card/baseInfo/listKey').reply(config => {
      let params = config.params;
      let mockBaseInfos = _BaseInfos.filter(baseInfo => {
      	if(params.logoUrl||params.logoUrl==''){ if( baseInfo.logoUrl.indexOf(params.logoUrl)>=0) return true;}
      	if(params.codeType||params.codeType==''){ if( baseInfo.codeType.indexOf(params.codeType)>=0) return true;}
      	if(params.isPayAndQrcode||params.isPayAndQrcode==''){ if( baseInfo.isPayAndQrcode.indexOf(params.isPayAndQrcode)>=0) return true;}
      	if(params.brandName||params.brandName==''){ if( baseInfo.brandName.indexOf(params.brandName)>=0) return true;}
      	if(params.title||params.title==''){ if( baseInfo.title.indexOf(params.title)>=0) return true;}
      	if(params.color||params.color==''){ if( baseInfo.color.indexOf(params.color)>=0) return true;}
      	if(params.notice||params.notice==''){ if( baseInfo.notice.indexOf(params.notice)>=0) return true;}
      	if(params.description||params.description==''){ if( baseInfo.description.indexOf(params.description)>=0) return true;}
      	if(params.useCustomCode||params.useCustomCode==''){ if( baseInfo.useCustomCode.indexOf(params.useCustomCode)>=0) return true;}
      	if(params.bindOpenid||params.bindOpenid==''){ if( baseInfo.bindOpenid.indexOf(params.bindOpenid)>=0) return true;}
      	if(params.servicePhone||params.servicePhone==''){ if( baseInfo.servicePhone.indexOf(params.servicePhone)>=0) return true;}
      	if(params.useAllLocations||params.useAllLocations==''){ if( baseInfo.useAllLocations.indexOf(params.useAllLocations)>=0) return true;}
      	if(params.centerTitle||params.centerTitle==''){ if( baseInfo.centerTitle.indexOf(params.centerTitle)>=0) return true;}
      	if(params.centerSubTitle||params.centerSubTitle==''){ if( baseInfo.centerSubTitle.indexOf(params.centerSubTitle)>=0) return true;}
      	if(params.centerUrl||params.centerUrl==''){ if( baseInfo.centerUrl.indexOf(params.centerUrl)>=0) return true;}
      	if(params.customUrlName||params.customUrlName==''){ if( baseInfo.customUrlName.indexOf(params.customUrlName)>=0) return true;}
      	if(params.customUrl||params.customUrl==''){ if( baseInfo.customUrl.indexOf(params.customUrl)>=0) return true;}
      	if(params.customUrlSubTitle||params.customUrlSubTitle==''){ if( baseInfo.customUrlSubTitle.indexOf(params.customUrlSubTitle)>=0) return true;}
      	if(params.promotionUrlName||params.promotionUrlName==''){ if( baseInfo.promotionUrlName.indexOf(params.promotionUrlName)>=0) return true;}
      	if(params.promotionUrl||params.promotionUrl==''){ if( baseInfo.promotionUrl.indexOf(params.promotionUrl)>=0) return true;}
      	if(params.promotionUrlSubTitle||params.promotionUrlSubTitle==''){ if( baseInfo.promotionUrlSubTitle.indexOf(params.promotionUrlSubTitle)>=0) return true;}
      	if(params.getLimit||params.getLimit==''){ if( baseInfo.getLimit.indexOf(params.getLimit)>=0) return true;}
      	if(params.canShare||params.canShare==''){ if( baseInfo.canShare.indexOf(params.canShare)>=0) return true;}
      	if(params.canGiveFriend||params.canGiveFriend==''){ if( baseInfo.canGiveFriend.indexOf(params.canGiveFriend)>=0) return true;}
      	if(params.needPushOnView||params.needPushOnView==''){ if( baseInfo.needPushOnView.indexOf(params.needPushOnView)>=0) return true;}
      	if(params.customAppBrandUserName||params.customAppBrandUserName==''){ if( baseInfo.customAppBrandUserName.indexOf(params.customAppBrandUserName)>=0) return true;}
      	if(params.customAppBrandPass||params.customAppBrandPass==''){ if( baseInfo.customAppBrandPass.indexOf(params.customAppBrandPass)>=0) return true;}
      	if(params.centerAppBrandUserName||params.centerAppBrandUserName==''){ if( baseInfo.centerAppBrandUserName.indexOf(params.centerAppBrandUserName)>=0) return true;}
      	if(params.centerAppBrandPass||params.centerAppBrandPass==''){ if( baseInfo.centerAppBrandPass.indexOf(params.centerAppBrandPass)>=0) return true;}
      	if(params.promotionAppBrandUserName||params.promotionAppBrandUserName==''){ if( baseInfo.promotionAppBrandUserName.indexOf(params.promotionAppBrandUserName)>=0) return true;}
      	if(params.promotionAppBrandPass||params.promotionAppBrandPass==''){ if( baseInfo.promotionAppBrandPass.indexOf(params.promotionAppBrandPass)>=0) return true;}
      	if(params.activateAppBrandUserName||params.activateAppBrandUserName==''){ if( baseInfo.activateAppBrandUserName.indexOf(params.activateAppBrandUserName)>=0) return true;}
      	if(params.activateAppBrandPass||params.activateAppBrandPass==''){ if( baseInfo.activateAppBrandPass.indexOf(params.activateAppBrandPass)>=0) return true;}
      	if(params.id||params.id==''){ if( baseInfo.id.indexOf(params.id)>=0) return true;}
      	if(params.cardPkId||params.cardPkId==''){ if( baseInfo.cardPkId.indexOf(params.cardPkId)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockBaseInfos
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/card/baseInfo/list').reply(config => {
      let params = config.params;
      let mockBaseInfos = _BaseInfos.filter(baseInfo => {
      	var isTrue=false;
      	if(params.logoUrl||params.logoUrl==''){if(baseInfo.logoUrl.indexOf(params.logoUrl)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.codeType||params.codeType==''){if(baseInfo.codeType.indexOf(params.codeType)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isPayAndQrcode||params.isPayAndQrcode==''){if(baseInfo.isPayAndQrcode.indexOf(params.isPayAndQrcode)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.brandName||params.brandName==''){if(baseInfo.brandName.indexOf(params.brandName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.title||params.title==''){if(baseInfo.title.indexOf(params.title)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.color||params.color==''){if(baseInfo.color.indexOf(params.color)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.notice||params.notice==''){if(baseInfo.notice.indexOf(params.notice)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.description||params.description==''){if(baseInfo.description.indexOf(params.description)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.useCustomCode||params.useCustomCode==''){if(baseInfo.useCustomCode.indexOf(params.useCustomCode)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bindOpenid||params.bindOpenid==''){if(baseInfo.bindOpenid.indexOf(params.bindOpenid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.servicePhone||params.servicePhone==''){if(baseInfo.servicePhone.indexOf(params.servicePhone)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.useAllLocations||params.useAllLocations==''){if(baseInfo.useAllLocations.indexOf(params.useAllLocations)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.centerTitle||params.centerTitle==''){if(baseInfo.centerTitle.indexOf(params.centerTitle)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.centerSubTitle||params.centerSubTitle==''){if(baseInfo.centerSubTitle.indexOf(params.centerSubTitle)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.centerUrl||params.centerUrl==''){if(baseInfo.centerUrl.indexOf(params.centerUrl)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.customUrlName||params.customUrlName==''){if(baseInfo.customUrlName.indexOf(params.customUrlName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.customUrl||params.customUrl==''){if(baseInfo.customUrl.indexOf(params.customUrl)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.customUrlSubTitle||params.customUrlSubTitle==''){if(baseInfo.customUrlSubTitle.indexOf(params.customUrlSubTitle)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.promotionUrlName||params.promotionUrlName==''){if(baseInfo.promotionUrlName.indexOf(params.promotionUrlName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.promotionUrl||params.promotionUrl==''){if(baseInfo.promotionUrl.indexOf(params.promotionUrl)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.promotionUrlSubTitle||params.promotionUrlSubTitle==''){if(baseInfo.promotionUrlSubTitle.indexOf(params.promotionUrlSubTitle)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.getLimit||params.getLimit==''){if(baseInfo.getLimit.indexOf(params.getLimit)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canShare||params.canShare==''){if(baseInfo.canShare.indexOf(params.canShare)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.canGiveFriend||params.canGiveFriend==''){if(baseInfo.canGiveFriend.indexOf(params.canGiveFriend)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.needPushOnView||params.needPushOnView==''){if(baseInfo.needPushOnView.indexOf(params.needPushOnView)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.customAppBrandUserName||params.customAppBrandUserName==''){if(baseInfo.customAppBrandUserName.indexOf(params.customAppBrandUserName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.customAppBrandPass||params.customAppBrandPass==''){if(baseInfo.customAppBrandPass.indexOf(params.customAppBrandPass)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.centerAppBrandUserName||params.centerAppBrandUserName==''){if(baseInfo.centerAppBrandUserName.indexOf(params.centerAppBrandUserName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.centerAppBrandPass||params.centerAppBrandPass==''){if(baseInfo.centerAppBrandPass.indexOf(params.centerAppBrandPass)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.promotionAppBrandUserName||params.promotionAppBrandUserName==''){if(baseInfo.promotionAppBrandUserName.indexOf(params.promotionAppBrandUserName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.promotionAppBrandPass||params.promotionAppBrandPass==''){if(baseInfo.promotionAppBrandPass.indexOf(params.promotionAppBrandPass)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.activateAppBrandUserName||params.activateAppBrandUserName==''){if(baseInfo.activateAppBrandUserName.indexOf(params.activateAppBrandUserName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.activateAppBrandPass||params.activateAppBrandPass==''){if(baseInfo.activateAppBrandPass.indexOf(params.activateAppBrandPass)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(baseInfo.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.cardPkId||params.cardPkId==''){if(baseInfo.cardPkId.indexOf(params.cardPkId)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockBaseInfos
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockBaseInfos.length;
      mockBaseInfos = mockBaseInfos.filter((baseInfo, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockBaseInfos,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/card/baseInfo/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _BaseInfos = _BaseInfos.filter(baseInfo => baseInfo.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/card/baseInfo/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _BaseInfos = _BaseInfos.filter(baseInfo => !params.includes(baseInfo.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/card/baseInfo/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { logoUrl,codeType,isPayAndQrcode,brandName,title,color,notice,description,useCustomCode,bindOpenid,servicePhone,useAllLocations,centerTitle,centerSubTitle,centerUrl,customUrlName,customUrl,customUrlSubTitle,promotionUrlName,promotionUrl,promotionUrlSubTitle,getLimit,canShare,canGiveFriend,needPushOnView,customAppBrandUserName,customAppBrandPass,centerAppBrandUserName,centerAppBrandPass,promotionAppBrandUserName,promotionAppBrandPass,activateAppBrandUserName,activateAppBrandPass,id,cardPkId } = params;
      _BaseInfos.some(baseInfo => {
        if (baseInfo.id === id) {
			baseInfo.logoUrl = logoUrl;
			baseInfo.codeType = codeType;
			baseInfo.isPayAndQrcode = isPayAndQrcode;
			baseInfo.brandName = brandName;
			baseInfo.title = title;
			baseInfo.color = color;
			baseInfo.notice = notice;
			baseInfo.description = description;
			baseInfo.useCustomCode = useCustomCode;
			baseInfo.bindOpenid = bindOpenid;
			baseInfo.servicePhone = servicePhone;
			baseInfo.useAllLocations = useAllLocations;
			baseInfo.centerTitle = centerTitle;
			baseInfo.centerSubTitle = centerSubTitle;
			baseInfo.centerUrl = centerUrl;
			baseInfo.customUrlName = customUrlName;
			baseInfo.customUrl = customUrl;
			baseInfo.customUrlSubTitle = customUrlSubTitle;
			baseInfo.promotionUrlName = promotionUrlName;
			baseInfo.promotionUrl = promotionUrl;
			baseInfo.promotionUrlSubTitle = promotionUrlSubTitle;
			baseInfo.getLimit = getLimit;
			baseInfo.canShare = canShare;
			baseInfo.canGiveFriend = canGiveFriend;
			baseInfo.needPushOnView = needPushOnView;
			baseInfo.customAppBrandUserName = customAppBrandUserName;
			baseInfo.customAppBrandPass = customAppBrandPass;
			baseInfo.centerAppBrandUserName = centerAppBrandUserName;
			baseInfo.centerAppBrandPass = centerAppBrandPass;
			baseInfo.promotionAppBrandUserName = promotionAppBrandUserName;
			baseInfo.promotionAppBrandPass = promotionAppBrandPass;
			baseInfo.activateAppBrandUserName = activateAppBrandUserName;
			baseInfo.activateAppBrandPass = activateAppBrandPass;
			baseInfo.id = id;
			baseInfo.cardPkId = cardPkId
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/card/baseInfo/add').reply(config => {
      var params = JSON.parse( config.data );
      let { logoUrl,codeType,isPayAndQrcode,brandName,title,color,notice,description,useCustomCode,bindOpenid,servicePhone,useAllLocations,centerTitle,centerSubTitle,centerUrl,customUrlName,customUrl,customUrlSubTitle,promotionUrlName,promotionUrl,promotionUrlSubTitle,getLimit,canShare,canGiveFriend,needPushOnView,customAppBrandUserName,customAppBrandPass,centerAppBrandUserName,centerAppBrandPass,promotionAppBrandUserName,promotionAppBrandPass,activateAppBrandUserName,activateAppBrandPass,id,cardPkId } = params;
      _BaseInfos.push({
		logoUrl:logoUrl,
		codeType:codeType,
		isPayAndQrcode:isPayAndQrcode,
		brandName:brandName,
		title:title,
		color:color,
		notice:notice,
		description:description,
		useCustomCode:useCustomCode,
		bindOpenid:bindOpenid,
		servicePhone:servicePhone,
		useAllLocations:useAllLocations,
		centerTitle:centerTitle,
		centerSubTitle:centerSubTitle,
		centerUrl:centerUrl,
		customUrlName:customUrlName,
		customUrl:customUrl,
		customUrlSubTitle:customUrlSubTitle,
		promotionUrlName:promotionUrlName,
		promotionUrl:promotionUrl,
		promotionUrlSubTitle:promotionUrlSubTitle,
		getLimit:getLimit,
		canShare:canShare,
		canGiveFriend:canGiveFriend,
		needPushOnView:needPushOnView,
		customAppBrandUserName:customAppBrandUserName,
		customAppBrandPass:customAppBrandPass,
		centerAppBrandUserName:centerAppBrandUserName,
		centerAppBrandPass:centerAppBrandPass,
		promotionAppBrandUserName:promotionAppBrandUserName,
		promotionAppBrandPass:promotionAppBrandPass,
		activateAppBrandUserName:activateAppBrandUserName,
		activateAppBrandPass:activateAppBrandPass,
		id:id,
		cardPkId:cardPkId
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};